package com.ygo.feihua.adapter;


import android.content.*;
import android.os.*;
import android.support.v7.widget.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import com.msk86.ygoroid.*;
import com.qnw.CardGroupManagement.*;
import com.ygo.feihua.*;
import com.ygo.feihua.service.*;
import com.ygo.feihua.util.*;
import java.util.*;

public class AdapterBkMk extends RecyclerView.Adapter<AdapterBkMk.ViewHolder>
{

	private List<Map<String,Object>> data =new ArrayList<Map<String,Object>>();
	private Context context;

	private DialogUtils du;
	private Gongju gj;

	private String lx;
	public AdapterBkMk(Context context,List<Map<String,Object>> data,String lx){
		this.context=context;
		this.data=data;
		gj=Gongju.getdx(context);
		du=DialogUtils.getdx(context);
		this.lx=lx;
	}
	
	@Override
	public AdapterBkMk.ViewHolder onCreateViewHolder(ViewGroup p1, int p2)
	{
		View v=LayoutInflater.from(p1.getContext()).inflate(R.layout.item_bk_mk, null);
		// TODO: Implement this method
		return new ViewHolder(v);
	}

	@Override
	public void onBindViewHolder(AdapterBkMk.ViewHolder vh, final int position)
	{
		
		vh.mk_name.setText((String)data.get(position).get("name"));
		vh.mk_tb.setImageResource(data.get(position).get("tb"));
	
		vh.v.setOnLongClickListener(new OnLongClickListener(){

				@Override
				public boolean onLongClick(View p1)
				{
					View[] v=du.dialogt(false,"","创建桌面快捷方式?");
					Button b1,b2;
					b1=(Button) v[0];
					b2=(Button) v[1];
					b1.setText("取消");
					b2.setText("创建");
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								du.dis();
								// TODO: Implement this method
							}
						});

					b2.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								du.dis();
								Intent addIntent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
								String name="";
								Intent intt = null;
								int tb = 0;
								switch(lx){
									case "手机版游戏王":
										name=(String) data.get(position).get("name");
										tb=data.get(position).get("tb");
										switch(position){
											case 0:
												intt=IntentUtil.getAppIntent("com.ygo.feihua","com.ygo.feihua.NewKatuxiazai");
												break;
											case 1:
												intt=new Intent("com.ygo.feihua.intent.action.ZhutiZhuye");
												break;
											case 2:
												gj.show("该板块不支持创建快捷方式");
												break;
											case 3:
												intt=IntentUtil.getAppIntent("com.ygo.feihua","com.qnw.CardGroupManagement.G5");
												break;
											case 4:
												intt=new Intent("com.ygo.feihua.intent.action.J5");
												break;
											case 5:
												intt=new Intent("com.ygo.feihua.intent.action.H5");
												break;
											case 6:
												intt=new Intent("com.ygo.feihua.intent.action.E5");
												break;
											case 7:
												intt=new Intent("com.ygo.feihua.intent.action.I5");
												break;
											case 8:
												intt=new Intent("com.ygo.feihua.intent.action.F5");
												break;
										}
										break;
									case "实卡相关":
										name=(String) data.get(position).get("name");
										tb=data.get(position).get("tb");
										switch(position){
											case 0:
												intt=new Intent("com.ygo.feihua.intent.action.KadianZhuye");
												break;
											case 1:
												intt=new Intent("com.ygo.feihua.intent.action.D5");
												break;
											case 2:
												intt=new Intent("com.ygo.feihua.intent.action.YGOActivity");
												break;
											case 3:
												intt=new Intent("com.ygo.feihua.intent.action.ServiceKacha");
												break;
										}
										break;
									case "YGOPRO战队联盟":
										name=(String) data.get(position).get("name");
										tb=data.get(position).get("tb");
										switch(position){
											case 0:
												intt=new Intent("com.ygo.feihua.intent.action.NewPaibiao");
												break;
											case 1:
												intt=IntentUtil.getUrlIntent(context,"https://www.ygobbs.com/");
												break;
										}

										break;

									case "其他":
										name=(String) data.get(position).get("name");
										tb=data.get(position).get("tb");
										switch(position){
											case 0:
												intt=new Intent("com.ygo.feihua.intent.action.RobotFeihua");
												break;
											case 1:
												intt=IntentUtil.getUrlIntent(context,"http://ygo233.com");
												break;
										}
										break;
								}
								if(!name.equals("")&&intt!=null&&tb!=0){
									//intt.setPackage("com.ygo.feihua");
									Parcelable icon=Intent.ShortcutIconResource.fromContext(context,tb);
									//Intent myIntent=new Intent(context,NewPaibiao.class);
									addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
									addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
									addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,intt);
									context.sendBroadcast(addIntent);

								}
								// TODO: Implement this method
							}
						});

					
					
					// TODO: Implement this method
					return true;
				}
			});
			
		vh.v.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					switch(lx){
						case "手机版游戏王":
							switch(position){
								case 0:
									context.startActivity(new Intent(context,NewKatuxiazai.class));
									break;
								case 1:
									context.startActivity(new Intent(context,ZhutiZhuye.class));
									break;
								
								case 2:

									Intent i1=IntentUtil.getAppIntent(context,"com.legendhan.mose2");
									if(i1!=null){
										context.startActivity(i1);
									}else{			
										View[] v=du.dialogt(false,"","好像没安装卡图DIY软件耶╮（╯＿╰）╭\n是否去下载呢");
										Button b1=(Button) v[0];
										Button b2=(Button) v[1];
										b1.setText("算了");
										b2.setText("去吧");
										b1.setOnClickListener(new OnClickListener(){

												@Override
												public void onClick(View p1)
												{
													du.dis();
													// TODO: Implement this method
												}
											});
										b2.setOnClickListener(new OnClickListener(){

												@Override
												public void onClick(View p1)
												{
													context.startActivity(IntentUtil.getUrlIntent(context,Gongju.URL_DOWNLOAD_XYSE));

													// TODO: Implement this method
												}
											});				
									}

									break;
							case 3:

									context.startActivity(new Intent(context,G5.class));
									break;
								case 4:
									context.startActivity(new Intent(context,J5.class));
									break;
								case 5:
									context.startActivity(new Intent(context,H5.class));
									break;
								case 6:
									context.startActivity(new Intent(context,E5.class));
									break;
								case 7:
									context.startActivity(new Intent(context,I5.class));
									break;
								case 8:
									context.startActivity(new Intent(context,F5.class));
									break;
							}
							break;
						case "实卡相关":
							switch(position){
								case 0:
									context.startActivity(new Intent(context,KadianZhuye.class));
									break;
								case 1:
									context.startActivity(new Intent(context,D5.class));
									break;
								case 2:
									context.startActivity(new Intent(context,YGOActivity.class));
									break;
								case 3:
									context.startService(new Intent(context,ServiceKacha.class));
									break;

							}
							break;
						case "YGOPRO战队联盟":
							switch(position){
								case 0:
									context.startActivity(new Intent(context,NewPaibiao.class));
									break;
								case 1:

									context.startActivity(IntentUtil.getUrlIntent(context,"https://www.ygobbs.com/"));
									break;
							}
							break;
						case "其他":
							switch(position){
								case 0:
									context.startActivity(new Intent(context,RobotFeihua.class));
									break;
								case 1:
									context.startActivity(IntentUtil.getUrlIntent(context,"http://ygo233.com"));
									break;
							}

							break;
					}
					
					// TODO: Implement this method
				}
			});
		// TODO: Implement this method
	}

	@Override
	public int getItemCount()
	{
		return data.size();
	}
	
	
	class ViewHolder extends RecyclerView.ViewHolder{
		ImageView mk_tb;
		TextView mk_name;
		View v;
		
		public ViewHolder(View v){
			super(v);
			this.v=v;
			mk_name=(TextView)v.findViewById(R.id.mk_name);
			mk_tb=(ImageView)v.findViewById(R.id.mk_tb);
		}
	}
	
	
	}
